package ds.factcom.view.ui.client;

import java.awt.BorderLayout;
import java.util.Iterator;
import java.util.List;

import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import ds.factcom.controller.client.ClientController;

@SuppressWarnings("serial")
public class ClientDebtorView extends JDialog {


		
		private final ClientController clientController;
		private List<String> listDebtor;
	
	public ClientDebtorView(ClientController clientController) {
		this.clientController = clientController;
		listDebtor = this.clientController.findClientDebtor();
	}
	
	
	public void showClientDebtor(){
		
		JFrame frame = new JFrame("Listado de Deudores");
			
			Object[] columns = {"Deudor"};
			Object data[][] = new Object[listDebtor.size()][1];
			
			
			
			
			if( listDebtor.size() != 0 ){
				int i =0;
				for (Iterator<String> iterator = listDebtor.iterator(); iterator.hasNext();) {
					String string = (String) iterator.next();
					data[i][0] = string;
					i++;
				}
				
				JTable table = new JTable( data, columns);
				  JScrollPane scrollPane = new JScrollPane(table);
				    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
				    frame.setSize(400, 300);
					frame.setLocation(400, 200);
				    frame.setVisible(true);
				    
			}else{
		
				showErrorMessage("Al momento No existen clientes deudores");
			}
			
			
			
			

			
			
			
			
			
	}

	public void listClientDebtor() {
		
		if( listDebtor.size() != 0 ){
			for (Iterator<String> iterator = listDebtor.iterator(); iterator.hasNext();) {
				String string = (String) iterator.next();
				System.out.println(string);
			}
		}else{
			System.out.println("Al momento No existen clientes deudores");
		}
	}
	
	
	protected void showErrorMessage(String message){
		
		JOptionPane.showMessageDialog(ClientDebtorView.this, message);
	}
	

}
